package com.ruoyi.system.api.factory;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.api.RemoteAiExperimentService;
import com.ruoyi.system.api.domain.AiExperiment;
import com.ruoyi.system.api.domain.AlgorithmType;
import com.ruoyi.system.api.domain.Partnerinfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;

@Component
public class RemoteAiExperimentFallbackFactory implements FallbackFactory<RemoteAiExperimentService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteLogFallbackFactory.class);

    @Override
    public RemoteAiExperimentService create(Throwable throwable) {

        // 记录错误日志
        log.error("远程调用失败，进入降级处理", throwable.getMessage());
        System.out.println("用户调用服务失败：{}"+throwable.getMessage());
        return new RemoteAiExperimentService() {

            @Override
            public R<Partnerinfo> add(AiExperiment aiExperiment) {
                return R.fail("远程调用失败，返回默认值" +throwable.getMessage());
            }

            @Override
            public List<AiExperiment> AiExperimentlist(AiExperiment aiExperiment) {
                log.error("远程调用失败，返回空列表");
                return Collections.emptyList();
            }

            @Override
            public List<AlgorithmType> AlgorithmTypelist(AlgorithmType algorithmType) {
                log.error("远程调用失败，返回空列表");
                return Collections.emptyList();
            }


        };
    }
}
